using System;
using System.Collections.Generic;
using System.Linq;
using Granite.DataAnnotations;
using Granite.Modeling;

namespace Rifts.Models.Characters
{
	public class Skill : EditableObjectModelBase
	{
		public string Name
		{
			get { return Get<String>("Name"); }
			set { Set(value, "Name"); }
		}

		public int? BaseScore
		{
			get { return Get<int?>("BaseScore"); }
			set { Set(value, "BaseScore"); }
		}

		public int? SecondaryBaseScore
		{
			get { return Get<int?>("SecondaryBaseScore"); }
			set { Set(value, "SecondaryBaseScore"); }
		}

		public int? PerLevel
		{
			get { return Get<int?>("PerLevel"); }
			set { Set(value, "PerLevel"); }
		}

		public int? OccBonus
		{
			get { return Get<int?>("OccBonus"); }
			set { Set(value, "OccBonus"); }
		}

		public int? IQBonus
		{
			get { return Get<int?>("IQBonus"); }
			set { Set(value, "IQBonus"); }
		}

		public int Level
		{
			get { return Get<int>(1, "Level"); }
			set { Set(value, "Level"); }
		}

		public bool IsHandToHand
		{
			get { return Get<bool>("IsHandToHand"); }
			set { Set(value, "IsHandToHand"); }
		}

		[CalculatedField("BaseScore,OccBonus,PerLevel,Level,IQBonus,CrossSkillBonus")]
		public int? Score
		{
			get
			{
				var result = BaseScore + (OccBonus ?? 0) + ((PerLevel ?? 0) * (Level - 1)) + (IQBonus ?? 0) + (CrossSkillBonus ?? 0);
				if (result > 98)
					return 98;
				return result;
			}
		}

		[CalculatedField("SecondaryBaseScore,OccBonus,PerLevel,Level,IQBonus,CrossSkillBonus")]
		public int? SecondaryScore
		{
			get
			{
				var result = SecondaryBaseScore + (OccBonus ?? 0) + ((PerLevel ?? 0) * (Level - 1)) + (IQBonus ?? 0) + (CrossSkillBonus ?? 0);
				if (result > 98)
					return 98;
				return result;
			}
		}

		public int? CrossSkillBonus
		{
			get { return Get<int?>("CrossSkillBonus"); }
			set { Set(value, "CrossSkillBonus"); }
		}

		/// <summary>
		/// The book/page the skill came from
		/// </summary>
		public string BookReference
		{
			get { return Get<String>("BookReference"); }
			set { Set(value, "BookReference"); }
		}

		///// <summary>
		///// This skill, race, or class that granted the ability
		///// </summary>
		//public string Source
		//{
		//	get { return Get<String>("Source"); }
		//	set { Set(value, "Source"); }
		//}

		public SkillType SkillType
		{
			get { return Get<SkillType>("SkillType"); }
			set { Set(value, "SkillType"); }
		}

		public AbilityCollection Abilities
		{
			get { return GetNew<AbilityCollection>("Abilities"); }
		} 
	}
}